package com.craney.testArray
{
	import com.craney.Emun.Emun;
	
	public class ArrayCallBack
	{
		public function ArrayCallBack()
		{

			var a:Array = new Array();
			a.push({Name:"Craney", Age:23, University:"Xidian"});
			a.push({Name:"Heather", Age:24, University:"Xidian"});
			a.push({Name:"Justin", Age:25, University:"Xidian"});
			a.push({Name:"Peng", Age:23, University:"JiaoDa"});
			a.push({Name:"Diedie", Age:23, University:"NanHang"});
			
			printArray(a);
			
			trace("Are all people in Xidian?");
			trace(a.every(isXidianer) ? "Yes!" : "No.");
			
			trace("Is someone of the people in Xidian?");
			trace(a.some(isXidianer) ? "Yes!" : "No.");
			
			trace("They are Xidianer:");
			printArray(a.filter(isXidianer).map(NewLessProperty));
			
			a.forEach(addMoreProperty);
			trace("After add more properties:");
			printArray(a);
		}
		
		private function addMoreProperty(item:*, index:int, ary:Array):void
		{
			if(item.Name=="Heather")
			{
				item.Gender = "female";
			}
			else
			{
				item["Gender"] = "male";
			}
		}
		
		private function NewLessProperty(item:*, index:int, ary:Array):Object
		{
			return {Name:item["Name"]};
		}
		

		private function isXidianer(item:*, index:int, ary:Array):Boolean
		{
			return item["University"]=="Xidian";
		}

		private function printArray(a:Array):void
		{
			for each(var e:* in a)
			{
				var s:String = "\t";
				for(var i:String in e)
				{
					s += i + "=" + e[i] + "\t";
				}
				trace(s);
			} 
		}
	}
}